/*
 * @Author: 黄展秀 10895739+huang-zhanxiu@user.noreply.gitee.com
 * @Date: 2023-03-14 21:43:07
 * @LastEditors: 黄展秀 10895739+huang-zhanxiu@user.noreply.gitee.com
 * @LastEditTime: 2023-05-17 16:19:30
 * @FilePath: \h5\src\router\index.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import Vue from 'vue'
import Router from 'vue-router'

//主界面相关组件
import mainIndex from '@/components/index'
import mainKnowledge from '@/components/Main/components/knowledge'
import knowinfo from '@/components/Main/components/knowinfo'
import mainExperts from '@/components/Main/components/experts'
import mainExpertsInfo from '@/components/Main/components/expertInfo'
import mainHome from '@/components/Main/components/Home'
import mainNews from '@/components/Main/components/news'
import mainNewsContent from '@/components/Main/components/newsContent'
import mainMyself from '@/components/Main/components/myself'
import weatherinfo from '@/components/Main/components/weatherinfo'

// 在线咨询的东西
import mainOnlineSeek from '@/components/Main/components/onlineSeek/onlineSeek'
import mainOnlineSeekSend from '@/components/Main/components/onlineSeek/components/send'
import mainOnlineSeekList from '@/components/Main/components/onlineSeek/components/list'
import mainOnlineSeekContent from '@/components/Main/components/onlineSeek/components/content'
// 智能问答的东西
import mainSmartSeek from '@/components/Main/components/smartSeek/smartSeek'
import mainSmartSeekSend from '@/components/Main/components/smartSeek/components/send'

// 远程培训的东西
import mainRemoteStudy from '@/components/Main/components/remoteStudy/remoteStudy'
import mainRemoteStudySource from '@/components/Main/components/remoteStudy/components/source'
import mainRemoteStudyContent from '@/components/Main/components/remoteStudy/components/content'

//登录相关组件
import loginPage from '@/components/Login/login'
import loginReg from '@/components/Login/reg'
import Error from '@/components/Error/Error'


Vue.use(Router)

const router = new Router({
  routes: [
    // 首页等的路由在这里操作
    { path: '/', redirect: '/home/', },
    {
      path: '/home', component: mainIndex, children: [
        // 首页
        { path: "/", name: "Home", component: mainHome, meta: { title: "首页" } },
        // 知识库页面
        { path: "knowledge", name: "Knowledge", component: mainKnowledge, meta: { title: "知识库列表" } },
        // {path:"knowinfo/:title/:content",name:"knowinfo",component:knowinfo,meta:{title:"知识信息"}},
        { path: "knowinfo", name: "knowinfo", component: knowinfo, meta: { title: "知识信息" } },
        { path: "weatherinfo", name: "weatherinfo", component: weatherinfo, meta: { title: "数据分析" } },
        //专家页面
        { path: "experts", name: "Experts", component: mainExperts, meta: { title: "专家库列表" } },
        { path: "expertsInfo", name: "ExpertsInfo", component: mainExpertsInfo, meta: { title: "专家详细" } },
        //在线咨询页面
        {
          path: "onlineSeek", component: mainOnlineSeek, meta: { title: "在线咨询" }, children: [
            { path: "/", name: "OnlineSeek", component: mainOnlineSeekList, meta: { title: "咨询列表" } },
            { path: "send", name: "OnlineSeekSend", component: mainOnlineSeekSend, meta: { title: "专家咨询" } },
            { path: "content", name: "OnlineSeekContent", component: mainOnlineSeekContent, meta: { title: "详细内容" } }
          ]
        },
        // 远程培训
        {
          path: "remoteStudy", component: mainRemoteStudy, meta: { title: "远程培训" }, children: [
            { path: "/", name: "RemoteStudySource", component: mainRemoteStudySource, meta: { title: "远程培训" } },
            { path: "content", name: "RemoteStudyContent", component: mainRemoteStudyContent, meta: { title: "详细内容" } }
          ]
        },
        // 智能问答页面
        {
          path: "smartSeek", component: mainSmartSeek, meta: { title: "AI智能客服" }, children: [
            { path: "/", name: "SmartSeek", component: mainSmartSeekSend, meta: { title: "AI智能客服" } },
          ]
        },
        // 新闻列表
        { path: "news", name: "News", component: mainNews, meta: { title: "新闻列表" } },
        { path: "newsContent", name: "NewsContent", component: mainNewsContent, meta: { title: "新闻内容" } },
        // 个人中心
        { path: "myself", name: "Myself", component: mainMyself, meta: { title: "个人中心" } }
      ]
    },

    //这里放的是与登录有关的路由
    // 登录
    { path: "/login", name: "Login", component: loginPage },
    // 注册
    { path: "/reg", name: "Reg", component: loginReg },
    { path: "/error", name: "error", component: Error },
    {
      path: '/:pathMatch(.*)',
      redirect: '/error'
    },
  ]
})

import cookie from "../../static/js/cookie";
router.beforeEach((to, from, next) => {
  if (to.name === "Login" || to.name === "Reg") {
    next();
  } else {
    cookie.getCookie("login") === "1" ? next() : next({ name: "Login" });
  }
})
export default router;
